<?php

/*
 * Copyright by Sygma Media Inovasi Ω2013
 * 
 * Lead Programmer : Sony K Wibisono,S.Si,M.T.I
 * E-mail : sony@sonywibisono.com
 * 
 * Designer : Mr. Agus
 * 
 */
class Users {
    var $id;
    var $username;
    var $password;
    var $fullname;
    var $address;
    var $city;
    var $state;
    var $country;
    var $date_join;
    var $date_of_birth;
    var $group_id;


    function open(){
        global $db;
        $sql="select * from users where id=$id";
        $row=$db->fetch_row($sql);
        if (!empty($row)){
            extract($row);
            $this->username=$username;
            $this->password=$password;
            $this->fullname=$fullname;
            $this->address=$address;
            $this->city=$city;
            $this->state=$state;
            $this->country=$country;
            $this->date_join=$date_join;
            $this->date_of_birth=$date_of_birth;
            $this->group_id=$group_id;

        }
    }

    function openAll(){
        $sql="select * from users order by id asc";
        $result=$db->query($sql);
        return $db->fetch_array($result);
        
    }

    function insert(){
    global $db;
    $sql="insert into users values (null,'{$this->username}',
        '{$this->password}','{$this->fullname}',
        '{$this->address}','{$this->city}',
        '{$this->state}','{$this->country}',
        '{$this->date_join}','{$this->date_of_birth}',
        '{$this->group_id}')";
    $db->query($sql);
    return mysql_insert_id();
    }

    function update(){
        global $db;
        $sql="update users set username='{$this->username}',
            password='{$this->password}',fullname='{$this->fullname}',
            address='{$this->address}',city='{$this->city}',
            state='{$this->state}',country='{$this->country}',
            date_join='{$this->date_join}',date_of_birth='{$this->date_of_birth}',
            group_id='{$this->group_id}' where id=".$this->id;
        $db->query($sql);
    }

    function delete(){
        global $db;
        $sql="delete from users where id=".$this->id;
        $db->query($sql);
    }

}
?>
